<%--
  Created by IntelliJ IDEA.
  User: 88403
  Date: 2021/6/20
  Time: 23:30
  To change this template use File | Settings | File Templates.
--%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>

    <title>新闻管理</title>
    <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <script src="http://cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
    <script src="http://cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    <script type="text/javascript">
        function deleteNews(nid){
            var res = confirm("是否删除");
            if(res==true){
                location.href="${pageContext.request.contextPath}/news/deleteNews?nid="+nid;
            }
        }



    </script>
</head>
<body>
<%@include file="header.jsp"%>
<div class="main-wrap">

    <div class="crumb-wrap">
        <div class="crumb-list"><i class="icon-font"></i><a href="index.jsp">首页</a><span class="crumb-step">&gt;</span><span class="crumb-name">留言管理</span></div>
    </div>
    <div class="result-wrap">
            <div class="result-title">
                <div class="result-list">
                    <button  type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#myModal">添加新闻</button>&nbsp;&nbsp;
                   <label>新闻类型</label> <select class="btn btn-primary btn-sm" onchange="selecttype()" id="bytype">
                        <option selected></option>
                        <option>1</option>
                        <option>2</option>
                        <option>3</option>
                    </select>
                    <span><b><font color="blue">1为公司新闻；2为行业新闻;3为热点新闻</font></b></span>
                    <script>
                        function selecttype(){
                           var ntype=$("#bytype").val()
                            location.href="${pageContext.request.contextPath}/news/showNews?ntype="+ntype;
                        }
                    </script>
                    <!-- 弹出模态框 -->
                    <div class="modal fade"  tabindex="-1" role="dialog" id="myModal" >
                        <div class="modal-dialog" role="document" >
                            <div class="modal-content" style="height: 500px;width: 400px" >
                                <div class="modal-header" >
                                    <button type="button" class="close" data-dismiss="modal">
                                        <span>&times;</span>
                                    </button>
                                    <h4 class="modal-title">添加新闻</h4>
                                </div>
                                <form action="${pageContext.request.contextPath}/news/addNews" method="post" class="form-horizontal">
                                    <div class="motal-body" align="center" >
                                        <table class="result-tab" style="width: 350px">
                                            <td><label >类型：</label></td>
                                            <td><select name="ntype" value="" >
                                                <option selected>1</option>
                                                <option>2</option>
                                                <option>3</option>
                                            </select>
                                            </td>
                                            <tr>
                                                <td><label>新闻标题：</label></td>
                                                <td>
                                                    <textarea name="ntitle" value="" style="height: 80px;width: 240px"></textarea>
                                                 </td>
                                            </tr>
                                            <tr>
                                                <td><label>新闻内容：</label></td>
                                                <td>
                                                    <textarea type="text"  name="ncontent" value="" style="height: 250px;width: 240px" ></textarea>

                                            </tr>
                                        </table>

                                        <button type="submit" class="btn btn-primary">添加</button>

                                    </div>

                                </form>


                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="result-content">
                <table class="result-tab" width="100%">
                    <tr>

                        <th>序号</th>
                        <th>类型</th>
                        <th>标题</th>
                        <th>时间</th>
                        <th>操作</th>
                    </tr>
                    <c:forEach items="${pi.list}" var="n" varStatus="i">
                        <tr>
                            <td>${i.count}</td>
                            <c:if test="${n.ntype eq 1}">
                                <td>公司新闻</td>
                            </c:if>
                            <c:if test="${n.ntype eq 2}">
                                <td>行业新闻</td>
                            </c:if>
                            <c:if test="${n.ntype eq 3}">
                                <td>热点新闻</td>
                            </c:if>

                            <td>${n.ntitle}</td>
                            <td><fmt:formatDate value="${n.ntime}" pattern="yyy-MM-dd HH:mm:ss"/> </td>
                            <td>
                                <button onclick="deleteNews(${n.nid})" class="btn btn-danger btn-sm" >删除</button>&nbsp;
                            </td>

                        </tr>
                    </c:forEach>
                </table>
                <div class="Pages" align="center">
                    <span >目前在第<b>${pi.pageNum}</b>页,</span>
                    <span class="p_count">共有<b>${pi.pages}</b>页,</span>
                    <span class="p_total">本页共有<b>${pi.size}</b>条记录</span>
                    <span class="p_page">
                              <a href="${pageContext.request.contextPath}/news/showNews?pageNum=1" class="a_first">首页</a>
                           <c:if test="${pi.hasPreviousPage}">
                               <a href="${pageContext.request.contextPath}/news/showNews?pageNum=${pi.pageNum-1}" class="a_prev">上一页</a>
                           </c:if>
                            <c:forEach begin="1" end="${pi.pages}" var="index">
                                <c:if test="${pi.pageNum==index}">
                                    <li class="active" style="display: inline;">
                                        <a href="${pageContext.request.contextPath}/news/showNews?pageNum=${index}" style=" line-height: 20px;color: black; text-decoration: none;padding: 10px 10px;">${index}</a>
                                    </li>
                                </c:if>
                                <c:if test="${pi.pageNum!=index}">
                                    <li class="" style="display: inline;">
                                        <a href="${pageContext.request.contextPath}/news/showNews?pageNum=${index}" style=" line-height: 20px;color: black; text-decoration: none;padding: 10px 10px;">${index}</a>
                                    </li>
                                </c:if>
                            </c:forEach>

                            <c:if test="${pi.hasNextPage}">
                                <a href="${pageContext.request.contextPath}/news/showNews?pageNum=${pi.pageNum+1}" class="a_next">下一页</a>
                            </c:if>
                             <a href="${pageContext.request.contextPath}/news/showNews?pageNum=${pi.pages}" class="a_end">末页</a>
                          </span>
                </div>
            </div>

    </div>
</div>
</div>
</div>
</body>
</html>
